1 /*
2 * Created on 2004.10.17.
3 *
4 * In bigyo project
5 */
6
7
8 package net.sf.bigyo.container.jmx;
9
10 import javax.management.JMException;
11
12 import net.sf.bigyo.api.LifecycleListener;
13 import net.sf.bigyo.api.ReconfigurationManager;
14 import net.sf.bigyo.container.api.Constants;
15 import net.sf.bigyo.model.ComponentConfig;
16
17 import org.apache.log4j.LogManager;
18 import org.apache.log4j.Logger;
19
20 /***
21 * @author zsombor
22 *
23 * Created at 10:58:39 net.sf.bigyo.container.jmx.JMXPublisher
24 *
25 * @bigyo-component jmx-publisher
26 */
27 public class JMXPublisher implements LifecycleListener {
28
29 MX4JRemote jmxServer;
30 ReconfigurationManager reconf;
31
32 static final Logger LOG = LogManager.getLogger(JMXPublisher.class);
33
34 /***
35 * @bigyo-constructor
36 */
37 public JMXPublisher() {
38 }
39
40 /***
41 * @bigyo-depend remote-management
42 * @param jmxServer
43 */
44 public void setJMXRemote(MX4JRemote jmxServer) {
45 this.jmxServer = jmxServer;
46 }
47
48 /***
49 * @bigyo-depend bigyo:reconfiguration-manager
50 */
51 public void setReconfigurationManager(ReconfigurationManager r) {
52 this.reconf = r;
53 }
54
55 /*
56 * (non-Javadoc)
57 *
58 * @see net.sf.bigyo.api.LifecycleListener#componentCreated(java.lang.Object,
59 * net.sf.bigyo.model.ComponentConfig)
60 */
61 public void componentCreated(Object obj, ComponentConfig config) {
62 LOG.info("component created " + obj + " config:" + config.getInstanceName() + " from " + config.getClassAlias());
63
64 String mbeanImplName = Constants.getMBeanImplName(obj.getClass().getName());
65
66 try {
67 JMXEnabled jmxEnabled = (JMXEnabled) Class.forName(mbeanImplName).newInstance();
68 jmxEnabled.setService(obj);
69 jmxEnabled.setConfig(config);
70 jmxEnabled.setReconfigurationManager(reconf);
71
72 jmxServer.publishJMX(generateName(config), jmxEnabled);
73
74 } catch (InstantiationException e) {
75 LOG.warn("mbean not found for " + config.getInstanceName() + " from class " + config.getClassAlias() + ","
76 + e.getMessage(), e);
77 } catch (IllegalAccessException e) {
78 LOG.warn("mbean not found for " + config.getInstanceName() + " from class " + config.getClassAlias() + ","
79 + e.getMessage(), e);
80 } catch (ClassNotFoundException e) {
81 LOG.warn("mbean not found for " + config.getInstanceName() + " from class " + config.getClassAlias() + ","
82 + e.getMessage(), e);
83 } catch (ClassCastException e) {
84 LOG.fatal("ERROR IN MACHINE GENERATED CODE:" + e.getMessage(), e);
85 } catch (JMException e) {
86 LOG.warn("error during mbean publishing for " + config.getInstanceName() + " from class "
87 + config.getClassAlias() + "," + e.getMessage(), e);
88 }
89
90 }
91
92 /***
93 * @param config
94 * @return
95 */
96 protected String generateName(ComponentConfig config) {
97 return "bigyo:type=" + config.getClassAlias()
98 + (config.getProfile() != null ? ",profile=" + config.getProfile() : "") + ",service="
99 + config.getInstanceName();
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see net.sf.bigyo.api.LifecycleListener#componentDisposed(java.lang.Object)
106 */
107 public void componentDisposed(Object obj) {
108 LOG.info("component disposed " + obj);
109
110 }
111
112 /*
113 * (non-Javadoc)
114 *
115 * @see net.sf.bigyo.api.LifecycleListener#componentReconfigured(java.lang.Object,
116 * java.lang.Object, net.sf.bigyo.model.ComponentConfig)
117 */
118 public void componentReconfigured(Object obj, Object oldConfigBean, ComponentConfig newConfig) {
119 LOG.info("component reconfigured " + obj + " config:" + newConfig.getInstanceName());
120 }
121 }
This page was automatically generated by Maven